/*
 * wrapper linux semphore api, make it easy to use
 * author: yuyoufei86@qq.com 
 */

#ifndef SEM_OP_H
#define SEM_OP_H
#include <sys/types.h>
#include <sys/sem.h>

//sem union ,used in calls to semctl()
union semun {
    int val;
    struct semid_ds *buf;
    unsigned short *array;
#if defined(__linux__)
    struct seminfo *_buf;
#endif
};

// extern int is_use_semundo; //use SEM_UNDO during semop()?
// extern int is_retry_eintr; //retry if semop interrupt by signal handler?
int create_sem(key_t key, int init_val);
int get_sem(key_t key);
//int init_sem(int sem_id, int value);
int sem_p(int sem_id, int p_value);
int sem_v(int sem_id, int v_value);
int sem_p_undo(int sem_id, int p_value);
int sem_v_undo(int sem_id, int v_value);
#endif